package com.spr.Controller;

import com.spr.Entity.Book;
import com.spr.Entity.Press;
import com.spr.Service.PressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class PressController {
    @Autowired
    PressService pressService;

    @GetMapping("/FindAllBooks")
    public void FindAllBooks(){
        System.out.println("5.查询某个出版社出版的所有书籍");
        List<Book> books = pressService.FindAllBookBypname("清华出版社");
        for (Book book1 : books) {
            System.out.println(book1.getName());
        }
        System.out.println(books);
    }

    @GetMapping("/FindBookInformation")
    public void FindBookInform(){
        System.out.println("3.完成查询书籍的时候，把书籍表中的所有书籍信息都查询出来，包含出版社信息");
        Book book = pressService.FindBookInform("西游记");
        System.out.println("id：" + book.getId());
        System.out.println("书名：" + book.getName());
        System.out.println("作者：" + book.getAuthor());
        System.out.println("单价：" + book.getPrice());
        System.out.println("出版社：" + book.getPress().getPname());
    }

    @GetMapping("/FindBookInformation_ex_pressinf")
    public void FindBookInforma_ex_pressinf(){
        System.out.println("2.完成查询书籍的时候，把书籍表中的所有书籍信息都查询出来，不包含出版社");
        Book book = pressService.FindBookInformaexpname("人性的弱点");
        System.out.println("id：" + book.getId());
        System.out.println("书名：" + book.getName());
        System.out.println("作者：" + book.getAuthor());
        System.out.println("单价：" + book.getPrice());
    }

    @GetMapping("/Findallpress")
    public void Findallpress(){
        System.out.println("4.查询所有出版社");
        List<Press> press = pressService.FindAllPress();
        for (Press press1 : press) {
            System.out.println(press1.getPname());
        }
    }
}
